package com.tiger.auth;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: jksj
 * @description:
 * @author: tigerJay
 * @create: 2022-02-04 16:17
 **/
public class ApiRequest {
    private String baseUrl;
    private String token;
    private String appId;
    private long timestamp;

    public ApiRequest(){}
    public ApiRequest(String baseUrl,String token,String appId,long timestamp){
        this.baseUrl = baseUrl;
        this.appId = appId;
        this.token = token;
        this.timestamp = timestamp;
    }

    public static ApiRequest parseFromFullUrl(String fullUrl){
        ApiRequest apiRequest = new ApiRequest();
        String[] var1 = fullUrl.split("\\?");
        apiRequest.baseUrl = var1[0];
        Map<String,String> params = parseUrlParam2Map(var1[1]);
        apiRequest.appId = params.get("appId");
        apiRequest.timestamp = Long.valueOf(params.get("timestamp"));
        apiRequest.token = params.get("token");
        return apiRequest;
    }

    private static Map<String,String> parseUrlParam2Map(String param){
        Map<String,String> result = new HashMap<>();
        if(param == null || "".equals(param)){
            return result;
        }
        String[] var0 = param.split("&");
        for (int i = 0; i < var0.length; i++) {
            String[] var1 = var0[i].split("=");
            if(var1.length == 2){
                result.put(var1[0],var1[1]);
            }
        }
        return result;
    }

    public String getBaseUrl() {
        return baseUrl;
    }

    public String getToken() {
        return token;
    }

    public String getAppId() {
        return appId;
    }

    public long getTimestamp() {
        return timestamp;
    }
}
